package com.ghsc.ghxc.jsb.ui.home.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.home.bean.CommodityDetailBean
import com.ghsc.ghxc.jsb.ui.home.bean.ResultSku
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.home.activity
 * 类名：GoodsDetailVIewModel
 * 创建时间：2024/4/24 14:56
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class GoodsDetailVIewModel : BaseViewModel() {



    /**
     * 商品详情
     * @param id 商品id
     */
    var commodityDetailResult = MutableLiveData<BaseResponse<CommodityDetailBean>>()
    fun commodityDetail(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onCommodityDetail(paras) }
            executeResponse(
                response,
                { commodityDetailResult.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     * 规格
     */
    var skuItemResult = MutableLiveData<BaseResponse<ResultSku>>()
    fun skuItem(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onSkuItem(paras) }
            executeResponse(
                response,
                { skuItemResult.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
}